#name=MIDIPLUS X Max




"""
[[
	Surface:	MIDIPLUS X Max
	Developer:	MIDIPLUS-LouisWdey
	Version:	1.0.3

    Copyright (c) 2024 MIDIPLUS
]]
"""
#-----------------------------------------------------------------------------------------



import time
import midi
import ui
import sys
import mixer
import transport
import channels
import playlist
import patterns
import plugins
import device
import general

#-----------------------------------------------------------------------------------------
xKnob = 0x55
openPluginButton = 0x56             #X Knob click
xKnobData2 = 0x40                   #Decimal 64 

rewindButton = 0x72                 #Rewind
fastForwardButton =0x73             #FastForward
loopButton = 0x74                   #Loop
recordButton = 0x75                 #Record
playButton= 0x76	                #Play
stopButton = 0x77	                #Stop

undoButton = 0x18                    #Undo
redoButton = 0x19                   #Redo
soloButton = 0x1A                   #Solo
muteButton = 0x1B                   #Mute
metronomeButton = 0x1C              #Metronome
modeSwitchButton = 0x1D             #Song/Pattern mode switch
switchEditAreaButton = 0x1E		    #Edit area switch
saveProjectButton = 0x1F		    #Project file saving

knob1 = 0x6A
knob2 = 0x6B
knob3 = 0x6C
knob4 = 0x6D
knob5 = 0x6E
knob6 = 0x6F
knob7 = 0x70
knob8 = 0x71

fader1 = 0x57
fader2 = 0x58
fader3 = 0x59
fader4 = 0x5A
fader5 = 0x66
fader6 = 0x67
fader7 = 0x68
fader8 = 0x69

mod = 0x01
#-----------------------------------------------------------------------------------------------------------------------
#Invoke when opening FL
def OnInit():	
    print()
    print("Script loaded,welcome to use MIDIPLUS X Max")
    print()
    print("DeviceID:",device.getDeviceID())
    print()
    print("portNumber:",device.getPortNumber())
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x77, 0x7f, 0xf7]))

    #Plugin test cases
    # print(plugins.getParamCount(0,-1))
    # for i in range(plugins.getParamCount(0,-1)):
    #     print(i,plugins.getParamName(i,0))
    # for i in range(plugins.getParamCount(0,-1)):
    #     print(i,plugins.getParamValue(i,0))


#-----------------------------------------------------------------------------------------------------------------------
#Invoke when closing FL
def OnDeInit(): 
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1c, 0x00, 0xf7]))#metronome
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x74, 0x00, 0xf7]))#loop
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x75, 0x00, 0xf7]))#record
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x76, 0x00, 0xf7]))#play
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x77, 0x00, 0xf7]))#stop
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1B, 0x00, 0xf7]))#solo
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1A, 0x00, 0xf7]))#mute
#-----------------------------------------------------------------------------------------------------------------------
#Called from time to time
def OnIdle():
    """LED""" 
    LoopCheck()
    RecordCheck()
    PlayCheck()
    MixerSoloCheck()
    MixerMuteCheck()
    MetronomeCheck()
#-----------------------------------------------------------------------------------------------------------------------
def OnPitchBend(event):
    """process PitchBend"""
    event.handled = False
    # print(channels.getChannelPitch(0))  #from 0 start
    # channels.setChannelPitch(0,event.data1)
    if channels.selectedChannel(1) != -1 :
        if plugins.isValid(channels.selectedChannel()) : 
            channels.setChannelPitch(channels.selectedChannel(),(event.data2-64)*(1200/64),1)
            event.handled = True 
#-----------------------------------------------------------------------------------------------------------------------
# def OnKeyPressure(event):
# #   print("未开始")
#     print(event.midiId, event.data1, event.data2)   #Enable this line of code during debugging for easier information viewing
#-----------------------------------------------------------------------------------------------------------------------
# def OnChannelPressure(event):
# #   print("未开始")
#     print(event.midiId, event.data1, event.data2)   #Enable this line of code during debugging for easier information viewing
#-----------------------------------------------------------------------------------------------------------------------
def OnControlChange(event):
    event.handled = False	#unprocessed
    #print(event.midiId, event.data1, event.data2)	#Enable this line of code during debugging for easier information viewing
    # if ui.getFocusedPluginName() == "Sampler" or ui.getFocusedPluginName() == "Audio Clip" or ui.getFocusedPluginName() == "Layer" or ui.getFocusedPluginName() == "Auto clip" or ui.getFocusedPluginName() == "采样器" or ui.getFocusedPluginName() == "音频剪辑" or ui.getFocusedPluginName() == "层" or ui.getFocusedPluginName() == "自动剪辑":
    #     event.handled = True
    if event.data2 > 0:#improtant!!!
        if event.data1 == xKnob:       #To restrict data2 from triggering other knobs
            HandleXknob(event)
        elif event.data1 == openPluginButton:
            if(ui.getFocused(4)):
                ui.enter()
                handled = True
            elif(ui.getFocused(1)):
                showPlugin(event)
            elif(ui.getFocused(5)):
                showPlugin(event)
        elif event.data1 == rewindButton:
            Rewind(event)
        elif event.data1 == fastForwardButton:
            FastForward(event)
        elif event.data1 == loopButton:
            Loop(event)
        elif event.data1 == recordButton:
            Record(event)
        elif event.data1 == playButton:
            Play(event)
        elif event.data1 == stopButton:
            Stop(event)
        elif event.data1 == undoButton:
            Undo(event)
        elif event.data1 == redoButton:
            Redo(event)
        elif event.data1 == soloButton:
            Solo(event)
        elif event.data1 == muteButton:
            Mute(event)
        elif event.data1 == metronomeButton:
            Metronome(event)
        elif event.data1 == modeSwitchButton:
            SongModeSwitch(event)
        elif event.data1 == switchEditAreaButton:
            SwitchEditArea(event)
        elif event.data1 == saveProjectButton:
            SaveProject(event)
        elif ui.getFocusedPluginName() != '':
            HandlePlugin(event)
        elif event.data1 == mod:
            HandleModulation(event)
        elif ui.getFocused(0):  #0:Mixer
            MixerVolume(event)
            MixerPan(event)
        elif ui.getFocused(1):  #1:ChannelRack
            ChannelVolume(event)
            ChannelPan(event)
    elif event.data2 == 0:
        if event.data1 == rewindButton:
            Rewind(event)
        elif event.data1 == fastForwardButton:
            FastForward(event)
        elif ui.getFocusedPluginName() != '':
            HandlePlugin(event)
        elif event.data1 == mod:
            HandleModulation(event)
        elif ui.getFocused(0): #0:Mixer
            MixerVolume(event)
            MixerPan(event)
        elif ui.getFocused(1):  #1:ChannelRack
            ChannelVolume(event)
            ChannelPan(event)
        OtherLED_Close()
#-----------------------------------------------------------------------------------------------------------------------
#Open the functions of the current plugin     
def showPlugin(event) :
    if event.data2 == 0x7F :  
        if channels.selectedChannel(1) != -1 :
            channels.showEditor(channels.selectedChannel())      
            event.handled = True   
    else:#if obtain the plugin name, then proceed with the close operation
        if ui.getFocusedPluginName() != '':
            print(ui.getFocusedPluginName())
            ui.escape()
            ui.setFocused(1)#1:Channel Rack
            event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
#Twist X Knob
def HandleXknob(event):
    if ui.getFocusedPluginName() == "Sampler" or ui.getFocusedPluginName() == "Audio Clip" or ui.getFocusedPluginName() == "Layer" or ui.getFocusedPluginName() == "Auto clip" or ui.getFocusedPluginName() == "采样器" or ui.getFocusedPluginName() == "音频剪辑" or ui.getFocusedPluginName() == "层" or ui.getFocusedPluginName() == "自动剪辑":
        event.handled = True
    else:
        current_position =  transport.getSongPos()  
        if event.midiId == midi.MIDI_CONTROLCHANGE:    #Check if the MIDI event type is a Control Change event
            focusedFormID = ui.getFocusedFormID()
            if event.data2 > 0:				#Check if there is data in data2 
                if ui.getFocusedPluginName() =='':
                    tag = 1
                else :
                    tag = 0
                if(ui.getFocused(2)):        #2 refers to the Playlist window   
                    if tag == 1:
                        #Calculate the direction of the knob rotation and update the playback position
                        if event.data2 < 64:
                            #Rotate left to decrease the playback position
                            current_position=transport.getSongPos(2)
                            #print(current_position)
                            current_position -= 24
                            if(current_position%24!=0):
                                current_position += 24-current_position%24
                            # current_position -= 0.001
                            #print(ui.getFocusedFormID())
                        else:
                            #Rotate right to increase the playback position
                            current_position=transport.getSongPos(2)
                            #print(current_position)
                            current_position += 24
                            if(current_position%24!=0):
                                current_position -=current_position%24
                            # current_position += 0.001

                        #Ensure the playback position does not exceed the limits
                        # current_position = max(current_position, 0)
                        # current_position = min(current_position, 1)

                        #Set the new playback position
                        transport.setSongPos(current_position,2)
                        event.handled = True
                
                elif tag == 0:
                    if event.data2 < xKnobData2:
                        if channels.selectedChannel(1) != -1 :
                            plugins.prevPreset(channels.selectedChannel())
                            event.handled = True
                    if event.data2 > xKnobData2:
                        if channels.selectedChannel(1) != -1 :
                            plugins.nextPreset(channels.selectedChannel())
                            event.handled = True
                elif event.data2 < xKnobData2:	#Use data2 to determine whether it's the previous or the next
                
                        #print('Previous Preset')	
                        ui.previous()			    #Send "previous" to the UI
                        event.handled = True		#Set to true to prevent FL from processing twice					
                elif event.data2 > xKnobData2:	 
                        #print('Next Preset')		
                        ui.next()			    #Send "next" to the UI
                        event.handled = True	#Processing complete
#-----------------------------------------------------------------------------------------------------------------------
def Rewind(event):
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x72, 0x7f, 0xf7]))        #Rewind LED open
    # step = 0.05
    # currentPosition = transport.getSongPos()
    # newPosition = currentPosition -step
    # if newPosition < 0:
    #     newPosition = 0         
    # transport.setSongPos(newPosition)
    # event.handled = True
    if event.data2 > 0:
        transport.rewind(2)
        event.handled = True
    elif event.data2 == 0:
        transport.rewind(0)
        event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def FastForward(event):
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x73, 0x7f, 0xf7]))        #fastforward led open
    # step = 0.05  #define the step size for each fast-forward (can be adjusted to achieve the desired fast-forward speed)
    # currentposition = transport.getsongpos()
    # newposition = currentposition + step
    # #ensure the new playback position does not exceed the total length of the song
    # if newposition > 1:
    #     newposition = 1
    # transport.setsongpos(newposition)
    # event.handled = true
    if event.data2 > 0:
        transport.fastForward(2)
        event.handled = True
    elif event.data2 == 0:
        transport.fastForward(0)
        event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def Loop(event):
    transport.globalTransport(midi.FPT_LoopRecord,1)
    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def Record(event):
    transport.record()
    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def Play(event):
    transport.globalTransport(midi.FPT_Play,1)
    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def Stop(event):
    transport.globalTransport(midi.FPT_Stop,1)
    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def Undo(event):
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x18, 0x7f, 0xf7]))        #Undo LED open
    general.undoUp()
    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def Redo(event):
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x19, 0x7f, 0xf7]))        #Redo LED open
    general.undoDown()
    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def Solo(event):
    focusedFormID = ui.getFocusedFormID()
    if(focusedFormID == 0):     #0 is Mixer
        mixer.soloTrack(mixer.trackNumber())
        event.handled = True
    elif(focusedFormID == 1):   #1 refers to the channel rack
        if channels.isChannelSolo(channels.selectedChannel()):
            for channelNum in range(0,channels.channelCount()):
                if channelNum != channels.selectedChannel():
                    channels.muteChannel(channelNum)
            event.handled = True
        else:
            channels.soloChannel(channels.selectedChannel(),True)
            event.handled = True
    elif(focusedFormID == 2):   #2 refers to the playlist
        selectedTrack = 0
        for trackNum in range(1, 501):
            if playlist.isTrackSelected(trackNum):
                selectedTrack = trackNum
        if playlist.isTrackSolo(selectedTrack):
            for trackNum in range(1,501):
                if trackNum != selectedTrack:
                    playlist.muteTrack(trackNum)
            event.handled = True
        else:
            playlist.soloTrack(selectedTrack)
            event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def Mute(event):
    focusedFormID = ui.getFocusedFormID()
    if(focusedFormID == 0):     #0 is Mixer
        #print(mixer.trackNumber())
        mixer.muteTrack(mixer.trackNumber())
        event.handled = True    
    elif(focusedFormID == 1):   #1 refers to the channel rack
        # print(channels.selectedChannel())
        channels.muteChannel(channels.selectedChannel())
        event.handled = True
    elif(focusedFormID == 2):   #2 refers to the playlist
        for trackNum in range(1, 501):
            if playlist.isTrackSelected(trackNum):
                playlist.muteTrack(trackNum)
        event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
#Open/close metronome
def Metronome(event):
    transport.globalTransport(midi.FPT_Metronome,1)
    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def SongModeSwitch(event):
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1D, 0x7f, 0xf7]))        #Song/Pattern mode switch LED open
    transport.setLoopMode()
    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def SwitchEditArea(event):
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1E, 0x7f, 0xf7]))        #Edit area switch Button LED open
    print(ui.getFocusedFormID())
    FormID = ui.getFocusedFormID()
    if FormID == 0:
        FormID = FormID+1
        ui.setFocused(FormID)
        event.handled = True
    elif FormID == 1:
        FormID = FormID+1
        ui.setFocused(FormID)
        event.handled = True
    elif FormID == 2:
        FormID = FormID+2
        ui.setFocused(FormID)
        event.handled = True
    elif FormID == 4:
        FormID = 0
        ui.setFocused(FormID)
        event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def SaveProject(event):
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1F, 0x7f, 0xf7]))        #Save project button LED open
    transport.globalTransport(midi.FPT_Save,1)
    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def HandlePlugin(event):
    if ui.getFocusedPluginName() == "Sampler" or ui.getFocusedPluginName() == "Audio Clip" or ui.getFocusedPluginName() == "Layer" or ui.getFocusedPluginName() == "Auto clip" or ui.getFocusedPluginName() == "采样器" or ui.getFocusedPluginName() == "音频剪辑" or ui.getFocusedPluginName() == "层" or ui.getFocusedPluginName() == "自动剪辑":
        event.handled = True
    else:
        plugin_name = plugins.getPluginName(channels.selectedChannel()) #Get the plugin name
        if plugin_name == 'FLEX' :
            PARAM_MAP = {   
                            87:10, #Fader
                            88:11,
                            89:12,
                            90:13,
                            102:14,
                            103:15,
                            104:16,
                            105:17,

                            1:21,       #Mod
                            
                            11:36,      #X Band

                            106: 18,  #Knob    
                            107: 22,  #The preceding number represents the actual physical knob and slider CC values
                            108: 25,  
                            109: 30,  
                            110: 0, 
                            111: 2,     
                            112: 3,   
                            113: 4
                        }
        elif plugin_name == 'FPC' :
            PARAM_MAP = {
                            87:8, #Fader
                            88:9,
                            89:10,
                            90:11,
                            102:12,
                            103:13,
                            104:14,
                            105:15,

                            1:-1,       #Mod
                            
                            11:-1,      #X Band

                            106: 4,  #Knob    
                            107: 5,  #The preceding number represents the actual physical knob and slider CC values
                            108: 6,  
                            109: 7,  
                            110: 0, 
                            111: 1,     
                            112: 2,   
                            113: 3
                        }
        elif plugin_name == 'FL Keys' :
            PARAM_MAP = {
                            87:5, #Fader
                            88:4,
                            89:3,
                            90:2,
                            102:15,
                            103:16,
                            104:17,
                            105:18,
                            
                            1:13,       #Mod

                            11:9,      #X Band

                            106: 0,  #Knob    
                            107: 1,  #The preceding number represents the actual physical knob and slider CC values
                            108: 14,  
                            109: 13,  
                            110: 12, 
                            111: 7,     
                            112: 11,   
                            113: 10
                        }
        elif plugin_name == 'Sytrus' :
            PARAM_MAP = {
                            87:11, #Fader
                            88:12,
                            89:13,
                            90:14,
                            102:15,
                            103:17,
                            104:20,
                            105:21,

                            1:19,       #Mod

                            11:18,      #X Band
                            
                            106: 18,  #Knob    
                            107: 19,  #The preceding number represents the actual physical knob and slider CC values
                            108: 1,  
                            109: 16,  
                            110: 3, 
                            111: 4,     
                            112: 5,   
                            113: 6
                        }
        elif plugin_name == 'GMS' :
            PARAM_MAP = {
                            87:32, #Fader
                            88:33,
                            89:45,
                            90:46,
                            102:47,
                            103:48,
                            104:20,
                            105:13,

                            1:19,       #Mod

                            11:18,      #X Band
                            
                            106: 56,  #Knob    
                            107: 58,  #The preceding number represents the actual physical knob and slider CC values
                            108: 57,  
                            109: 60,  
                            110: 24, 
                            111: 25,     
                            112: 26,   
                            113: 27
                        }
        elif plugin_name == 'Harmless' :
            PARAM_MAP = {
                            87:65, #Fader
                            88:66,
                            89:79,
                            90:80,
                            102:81,
                            103:82,
                            104:83,
                            105:84,

                            1:24,       #Mod

                            11:89,      #X Band
                            
                            106: 54,  #Knob    
                            107: 59,  #The preceding number represents the actual physical knob and slider CC values
                            108: 91,  
                            109: 97,  
                            110: 26, 
                            111: 27,     
                            112: 28,   
                            113: 31
                        }
        elif plugin_name == 'Harmor' :
            PARAM_MAP = {
                            87:34, #Fader
                            88:37,
                            89:27,
                            90:28,
                            102:29,
                            103:30,
                            104:31,
                            105:32,

                            1:773,       #Mod

                            11:772,      #X Band
                            
                            106: 52,  #Knob    
                            107: 57,  #The preceding number represents the actual physical knob and slider CC values
                            108: 438,  
                            109: 443,  
                            110: 772, 
                            111: 773,     
                            112: 774,   
                            113: 776
                        }
        elif plugin_name == 'Morphine' :
            PARAM_MAP = {
                            87:30, #Fader
                            88:31,
                            89:32,
                            90:33,
                            102:34,
                            103:35,
                            104:36,
                            105:37,

                            1:7,       #Mod

                            11:9,      #X Band
                            
                            106: 6,  #Knob    
                            107: 7,  #The preceding number represents the actual physical knob and slider CC values
                            108: 14,  
                            109: 17,  
                            110: 1, 
                            111: 8,     
                            112: 15,   
                            113: 19
                        }
        elif plugin_name == '3x Osc' :
            PARAM_MAP = {
                            87:6, #Fader
                            88:7,
                            89:13,
                            90:14,
                            102:3,
                            103:4,
                            104:5,
                            105:10,

                            1:111,       #Mod

                            11:110,      #X Band
                            
                            106: 1,  #Knob    
                            107: 8,  #The preceding number represents the actual physical knob and slider CC values
                            108: 15,  
                            109: 20,  
                            110: 2, 
                            111: 9,     
                            112: 16,   
                            113: 0
                        }
        elif plugin_name == 'Fruity DX10' :
            PARAM_MAP = {
                            87:5, #Fader
                            88:6,
                            89:7,
                            90:8,
                            102:9,
                            103:12,
                            104:14,
                            105:15,

                            1:111,       #Mod

                            11:110,      #X Band
                            
                            106: 11,  #Knob    
                            107: 21,  #The preceding number represents the actual physical knob and slider CC values
                            108: 13,  
                            109: 10,  
                            110: 0, 
                            111: 1,     
                            112: 2,   
                            113: -1
                        }
        elif plugin_name == 'BASSDRUM' or plugin_name == 'BassDrum':
            PARAM_MAP = {
                            87:16, #Fader
                            88:17,
                            89:18,
                            90:0,
                            102:19,
                            103:20,
                            104:23,
                            105:24,

                            1:14,       #Mod

                            11:21,      #X Band
                            
                            106: 2,  #Knob    
                            107: 8,  #The preceding number represents the actual physical knob and slider CC values
                            108: 7,  
                            109: 6,  
                            110: 1, 
                            111: 4,     
                            112: 3,   
                            113: 5
                        }
        elif plugin_name == 'Fruit kick' :
            PARAM_MAP = {
                            87:26, #Fader
                            88:27,
                            89:28,
                            90:29,
                            102:30,
                            103:31,
                            104:32,
                            105:33,
                            
                            1:94,       #Mod

                            11:93,      #X Band

                            106: 0,  #Knob    
                            107: 1,  #The preceding number represents the actual physical knob and slider CC values
                            108: 2,  
                            109: 3,  
                            110: 4, 
                            111: 5,     
                            112: 24,   
                            113: 25
                        }
        elif plugin_name == 'MiniSynth' :
            PARAM_MAP = {
                            87:21, #Fader
                            88:22,
                            89:23,
                            90:24,
                            102:25,
                            103:26,
                            104:27,
                            105:28,

                            1:4,       #Mod

                            11:0,      #X Band
                            
                            106: 8,  #Knob    
                            107: 9,  #The preceding number represents the actual physical knob and slider CC values
                            108: 19,  
                            109: 20,  
                            110: 12, 
                            111: 13,     
                            112: 14,   
                            113: 15
                        }
        elif plugin_name == 'PoiZone' :
            PARAM_MAP = {
                            87:22, #Fader
                            88:23,
                            89:24,
                            90:25,
                            102:26,
                            103:27,
                            104:28,
                            105:29,

                            1:43,       #Mod

                            11:71,      #X Band
                            
                            106: 18,  #Knob    
                            107: 19,  #The preceding number represents the actual physical knob and slider CC values
                            108: 9,  
                            109: 46,  
                            110: 11, 
                            111: 12,     
                            112: 13,   
                            113: 14
                        }
        elif plugin_name == 'Sakura' :
            PARAM_MAP = {
                            87:12, #Fader
                            88:13,
                            89:14,
                            90:15,
                            102:16,
                            103:17,
                            104:18,
                            105:25,

                            1:66,       #Mod

                            11:31,      #X Band
                            
                            106: 8,  #Knob    
                            107: 9,  #The preceding number represents the actual physical knob and slider CC values
                            108: 19,  
                            109: 20,  
                            110: 21, 
                            111: 22,     
                            112: 23,   
                            113: 24
                        }
        elif plugin_name == 'Fruity Envelope Controller' :
            PARAM_MAP = {
                            87:3, #Fader
                            88:4,
                            89:5,
                            90:6,
                            102:10,
                            103:11,
                            104:12,
                            105:13,

                            1:89,       #Mod

                            11:88,      #X Band
                            
                            106: 88,  #Knob    
                            107: 89,  #The preceding number represents the actual physical knob and slider CC values
                            108: 7,  
                            109: 2,  
                            110: 0, 
                            111: 1,     
                            112: 8,   
                            113: 9
                        }
        elif plugin_name == 'Ogun' :
            PARAM_MAP = {
                            87:49, #Fader
                            88:50,
                            89:51,
                            90:52,
                            102:53,
                            103:54,
                            104:55,
                            105:56,
                            
                            1:4,       #Mod

                            11:3,      #X Band

                            106: 17,  #Knob    
                            107: 18,  #The preceding number represents the actual physical knob and slider CC values
                            108: 25,  
                            109: 39,  
                            110: 5, 
                            111: 6,     
                            112: 7,   
                            113: 8
                        }
        elif plugin_name == 'BooBass' :
            PARAM_MAP = {
                            87:-1, #Fader
                            88:-1,
                            89:-1,
                            90:-1,
                            102:-1,
                            103:-1,
                            104:-1,
                            105:-1,

                            1:-1,       #Mod

                            11:-1,      #X Band
                            
                            106: 0,  #Knob    
                            107: 1,  #The preceding number represents the actual physical knob and slider CC values
                            108: 2,  
                            109: -1,  
                            110: -1, 
                            111: -1,     
                            112: -1,   
                            113: 8
                        }
        elif plugin_name == 'SimSynth Live' :
            PARAM_MAP = {
                            87:17, #Fader
                            88:18,
                            89:19,
                            90:20,
                            102:26,
                            103:27,
                            104:28,
                            105:29,

                            1:14,       #Mod

                            11:13,      #X Band
                            
                            106: 11,  #Knob    
                            107: 12,  #The preceding number represents the actual physical knob and slider CC values
                            108: 15,  
                            109: 16,  
                            110: 22, 
                            111: 23,     
                            112: 24,   
                            113: 25
                        }
        elif plugin_name == 'Autogun' :
            PARAM_MAP = {
                            87:-1, #Fader
                            88:-1,
                            89:-1,
                            90:-1,
                            102:-1,
                            103:-1,
                            104:-1,
                            105:-1,
                            
                            1:-1,       #Mod

                            11:-1,      #X Band

                            106: 0,  #Knob    
                            107: -1,  #The preceding number represents the actual physical knob and slider CC values
                            108: -1,  
                            109: -1,  
                            110: -1, 
                            111: -1,     
                            112: -1,   
                            113: -1
                        }
        elif plugin_name == 'PLUCKED!' :
            PARAM_MAP = {
                            87:-1, #Fader
                            88:-1,
                            89:-1,
                            90:-1,
                            102:-1,
                            103:-1,
                            104:-1,
                            105:-1,

                            1:1,       #Mod

                            11:-1,      #X Band
                            
                            106: 0,  #Knob    
                            107: 1,  #The preceding number represents the actual physical knob and slider CC values
                            108: 2,  
                            109: 3,  
                            110: 4, 
                            111: -1,     
                            112: -1,   
                            113: -1
                        }
        elif plugin_name == 'BeepMap' :
            PARAM_MAP = {
                            87:42, #Fader
                            88:43,
                            89:44,
                            90:45,
                            102:46,
                            103:47,
                            104:48,
                            105:49,

                            1:95,       #Mod

                            11:94,      #X Band
                            
                            106: 0,  #Knob    
                            107: 1,  #The preceding number represents the actual physical knob and slider CC values
                            108: 2,  
                            109: 3,  
                            110: 4, 
                            111: 5,     
                            112: 6,   
                            113: 8
                        }
        elif plugin_name == 'Toxic Biohazard' :
            PARAM_MAP = {
                            87:3, #Fader
                            88:4,
                            89:5,
                            90:6,
                            102:7,
                            103:8,
                            104:9,
                            105:11,

                            1:2,       #Mod

                            11:0,      #X Band
                            
                            106: 15,  #Knob    
                            107: 16,  #The preceding number represents the actual physical knob and slider CC values
                            108: 10,  
                            109: 1,  
                            110: 19, 
                            111: 20,     
                            112: 21,   
                            113: 22
                        }
        elif plugin_name == 'Fruity Dance' :
            PARAM_MAP = {
                            87:-1, #Fader
                            88:-1,
                            89:-1,
                            90:-1,
                            102:-1,
                            103:-1,
                            104:-1,
                            105:-1,

                            1:6,       #Mod

                            11:5,      #X Band
                            
                            106: 0,  #Knob    
                            107: 1,  #The preceding number represents the actual physical knob and slider CC values
                            108: 2,  
                            109: 3,  
                            110: 4, 
                            111: 5,     
                            112: 6,   
                            113: -1
                        }
        elif plugin_name == 'Drumaxx' :
            PARAM_MAP = {
                            87:706, #Fader
                            88:717,
                            89:718,
                            90:705,
                            102:706,
                            103:707,
                            104:708,
                            105:709,

                            1:27,       #Mod

                            11:26,      #X Band
                            
                            106: 0,  #Knob    
                            107: 44,  #The preceding number represents the actual physical knob and slider CC values
                            108: 88,  
                            109: 132,  
                            110: 176, 
                            111: 220,     
                            112: 264,   
                            113: 308
                        }
        elif plugin_name == 'Drumpad' :
            PARAM_MAP = {
                            87:2, #Fader
                            88:3,
                            89:4,
                            90:5,
                            102:6,
                            103:7,  
                            104:8,
                            105:9,

                            1:22,       #Mod

                            11:21,      #X Band
                            
                            106: 13,  #Knob    
                            107: 15,  #The preceding number represents the actual physical knob and slider CC values
                            108: 18,  
                            109: 24,  
                            110: 14, 
                            111: 16,     
                            112: 19,   
                            113: 25
                        }
        elif plugin_name == 'Slicex' :
            PARAM_MAP = {
                            87:2, #Fader
                            88:3,
                            89:4,
                            90:5,
                            102:6,
                            103:7,  
                            104:8,
                            105:9,

                            1:7,       #Mod

                            11:6,      #X Band
                            
                            106: 13,  #Knob    
                            107: 15,  #The preceding number represents the actual physical knob and slider CC values
                            108: 18,  
                            109: 24,  
                            110: 14, 
                            111: 16,     
                            112: 19,   
                            113: 25
                        }
        elif plugin_name == 'SoundFont Player' :
            PARAM_MAP = {
                            87:5, #Fader
                            88:6,
                            89:7,
                            90:8,
                            102:13,
                            103:14,  
                            104:15,
                            105:16,

                            1:4,       #Mod

                            11:11,      #X Band
                            
                            106: 12,  #Knob    
                            107: 4,  #The preceding number represents the actual physical knob and slider CC values
                            108: 2,  
                            109: 3,  
                            110: 9, 
                            111: 10,     
                            112: 11,   
                            113: -1
                        }
        elif plugin_name == 'Fruity granulizer' :
            PARAM_MAP = {
                            87:8, #Fader
                            88:9,
                            89:10,
                            90:11,
                            102:12,
                            103:13,  
                            104:14,
                            105:15,

                            1:-1,       #Mod

                            11:-1,      #X Band
                            
                            106: 0,  #Knob    
                            107: 1,  #The preceding number represents the actual physical knob and slider CC values
                            108: 2,  
                            109: 3,  
                            110: 7, 
                            111: 4,     
                            112: 5,   
                            113: 6
                        }
        elif plugin_name == 'Sawer' :
            PARAM_MAP = {
                            87:2, #Fader
                            88:3,
                            89:4,
                            90:5,
                            102:6,
                            103:7,  
                            104:8,
                            105:9,

                            1:45,       #Mod

                            11:46,      #X Band
                            
                            106: 27,  #Knob    
                            107: 28,  #The preceding number represents the actual physical knob and slider CC values
                            108: 11,  
                            109: 18,  
                            110: 32, 
                            111: 33,     
                            112: 34,   
                            113: 35
                        }
        elif plugin_name == 'Transistor Bass' :
            PARAM_MAP = {
                            87:28, #Fader
                            88:29,
                            89:30,
                            90:31,
                            102:32,
                            103:33,  
                            104:34,
                            105:35,

                            1:13,       #Mod

                            11:12,      #X Band
                            
                            106: 2,  #Knob    
                            107: 4,  #The preceding number represents the actual physical knob and slider CC values
                            108: 5,  
                            109: 6,  
                            110: 0, 
                            111: 1,     
                            112: 7,   
                            113: 8
                        }
        elif plugin_name == 'Kontakt 7' or plugin_name == 'Kontakt 6' or plugin_name == 'Kontakt 8':
            PARAM_MAP = {
                            87:8, #Fader
                            88:9,
                            89:10,
                            90:11,
                            102:12,
                            103:13,
                            104:14,
                            105:15,

                            1:4097,     #Mod

                            11:4107,      #X Band
                            
                            106: 0,  #Knob    
                            107: 1,  #The preceding number represents the actual physical knob and slider CC values
                            108: 2,  
                            109: 3,  
                            110: 4, 
                            111: 5,     
                            112: 6,   
                            113: 7
                        }
        elif plugin_name == 'HALion Sonic' or plugin_name == 'HALion':
            PARAM_MAP = {
                            87:17, #Fader
                            88:18,
                            89:19,
                            90:20,
                            102:21,
                            103:22,
                            104:23,
                            105:24,

                            1:4097,     #Mod

                            11:4107,      #X Band
                            
                            106: 9,  #Knob    
                            107: 10,  #The preceding number represents the actual physical knob and slider CC values
                            108: 11,  
                            109: 12,  
                            110: 13, 
                            111: 14,     
                            112: 15,   
                            113: 16
                        }
        elif plugin_name == 'Analog Lab V':
                    PARAM_MAP = {
                                    87:12, #Fader
                                    88:13,
                                    89:14,
                                    90:15,
                                    102:16,
                                    103:17,
                                    104:18,
                                    105:19,

                                    1:4097,     #Mod

                                    11:4107,      #X Band
                            
                                    106: 2,  #Knob    
                                    107: 4,  #The preceding number represents the actual physical knob and slider CC values
                                    108: 6,  
                                    109: 8,  
                                    110: 102, 
                                    111: 163,     
                                    112: 224,   
                                    113: 233
                                }
        else:
            PARAM_MAP = {
                            87:8, #Fader
                            88:9,
                            89:10,
                            90:11,
                            102:12,
                            103:13,
                            104:14,
                            105:15,

                            1:4097,     #Mod

                            11:4107,      #X Band
                            
                            106: 0,  #Knob    
                            107: 1,  #The preceding number represents the actual physical knob and slider CC values
                            108: 2,  
                            109: 3,  
                            110: 4, 
                            111: 5,     
                            112: 6,   
                            113: 7
                        }

            
            
        if event.status == 176:  #Add an additional check to prevent pitch bend and modulation wheel bugs temporarily. 
            cc_value = event.data1  #Get the CC value
            cc_mapped_param = PARAM_MAP.get(cc_value)  #Check if the CC value is in the parameter mapping
            if cc_mapped_param is not None: #If it's in the mapping
                value = event.data2 / 127  #Convert MIDI data to a value ranging from 0 to 1
                selected_channel = channels.selectedChannel() #Get the index of the selected channel
                if selected_channel != -1:  #If the selected channel is valid
                    plugins.setParamValue(value, cc_mapped_param, selected_channel)  #Set the plugin parameter value
                    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
def HandleModulation(event):
    modulation_value = event.data2
    for channel in range(16):
        midi_out = (0xB0 | channel, event.data1, event.data2)
        device.midiOutMsg(midi_out[0] + (midi_out[1] << 8) + (midi_out[2] << 16))
    event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
#Adjust Mixer Volume
def MixerVolume(event):
    if event.data1 == fader1:
        value = event.data2/127
        mixer.setTrackVolume(mixer.trackNumber(),value, 2)
        event.handled = True
    elif event.data1 == fader2:
        value = event.data2/127
        mixer.setTrackVolume(mixer.trackNumber()+1,value, 2)
        event.handled = True
    elif event.data1 == fader3:
        value = event.data2/127
        mixer.setTrackVolume(mixer.trackNumber()+2,value, 2)
        event.handled = True
    elif event.data1 == fader4:
        value = event.data2/127
        mixer.setTrackVolume(mixer.trackNumber()+3,value, 2)
        event.handled = True
    elif event.data1 == fader5:
        value = event.data2/127
        mixer.setTrackVolume(mixer.trackNumber()+4,value, 2)
        event.handled = True
    elif event.data1 == fader6:
        value = event.data2/127
        mixer.setTrackVolume(mixer.trackNumber()+5,value, 2)
        event.handled = True
    elif event.data1 == fader7:
        value = event.data2/127
        mixer.setTrackVolume(mixer.trackNumber()+6,value, 2)
        event.handled = True
    elif event.data1 == fader8:
        value = event.data2/127
        mixer.setTrackVolume(mixer.trackNumber()+7,value, 2)
        event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
#Adjust Mixer Pan
def MixerPan(event):
    if event.data1 == knob1:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        mixer.setTrackPan(mixer.trackNumber(),value, 2)
        event.handled = True
    elif event.data1 == knob2:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        mixer.setTrackPan(mixer.trackNumber()+1,value, 2)
        event.handled = True
    elif event.data1 == knob3:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        mixer.setTrackPan(mixer.trackNumber()+2,value, 2)
        event.handled = True
    elif event.data1 == knob4:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        mixer.setTrackPan(mixer.trackNumber()+3,value, 2)
        event.handled = True
    elif event.data1 == knob5:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        mixer.setTrackPan(mixer.trackNumber()+4,value, 2)
        event.handled = True
    elif event.data1 == knob6:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        mixer.setTrackPan(mixer.trackNumber()+5,value, 2)
        event.handled = True
    elif event.data1 == knob7:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        mixer.setTrackPan(mixer.trackNumber()+6,value, 2)
        event.handled = True
    elif event.data1 == knob8:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        mixer.setTrackPan(mixer.trackNumber()+7,value, 2)
        event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
#Adjust Channel Volume
def ChannelVolume(event):
    if event.data1 == fader1:
        value = event.data2/127
        channels.setChannelVolume(channels.selectedChannel(),value)
        event.handled = True
    if event.data1 == fader2:
        value = event.data2/127
        channels.setChannelVolume(channels.selectedChannel()+1,value)
        event.handled = True
    if event.data1 == fader3:
        value = event.data2/127
        channels.setChannelVolume(channels.selectedChannel()+2,value)
        event.handled = True
    if event.data1 == fader4:
        value = event.data2/127
        channels.setChannelVolume(channels.selectedChannel()+3,value)
        event.handled = True
    if event.data1 == fader5:
        value = event.data2/127
        channels.setChannelVolume(channels.selectedChannel()+4,value)
        event.handled = True
    if event.data1 == fader6:
        value = event.data2/127
        channels.setChannelVolume(channels.selectedChannel()+5,value)
        event.handled = True
    if event.data1 == fader7:
        value = event.data2/127
        channels.setChannelVolume(channels.selectedChannel()+6,value)
        event.handled = True
    if event.data1 == fader8:
        value = event.data2/127
        channels.setChannelVolume(channels.selectedChannel()+7,value)
        event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
#Adjust Channel Pan
def ChannelPan(event):
    if event.data1 == knob1:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        channels.setChannelPan(channels.selectedChannel(),value)
        event.handled = True
    elif event.data1 == knob2:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        channels.setChannelPan(channels.selectedChannel()+1,value)
        event.handled = True
    elif event.data1 == knob3:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        channels.setChannelPan(channels.selectedChannel()+2,value)
        event.handled = True
    elif event.data1 == knob4:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        channels.setChannelPan(channels.selectedChannel()+3,value)
        event.handled = True
    elif event.data1 == knob5:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        channels.setChannelPan(channels.selectedChannel()+4,value)
        event.handled = True
    elif event.data1 == knob6:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        channels.setChannelPan(channels.selectedChannel()+5,value)
        event.handled = True
    elif event.data1 == knob7:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        channels.setChannelPan(channels.selectedChannel()+6,value)
        event.handled = True
    elif event.data1 == knob8:
        value = round(event.data2*(128/127)-64)/64
        if value <=  0.984:
            value = value-0.1
        if value < 0.02 and value > -0.02:
            value = 0.0
        channels.setChannelPan(channels.selectedChannel()+7,value)
        event.handled = True
#-----------------------------------------------------------------------------------------------------------------------
#Metronome LED check
metronome = 0
def MetronomeCheck():
    global metronome  
    if ui.isMetronomeEnabled():
        if metronome == 0:
            metronome = 1
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1c, 0x7f, 0xf7]))
            print("Metronome is using")
    else:
        if metronome == 1:
            metronome = 0
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1c, 0x00, 0xf7]))
            print("Metronome is closing")
#-----------------------------------------------------------------------------------------------------------------------
#Loop LED check
loop = 0
def LoopCheck():
    global loop  
    if ui.isLoopRecEnabled():
        if loop == 0:
            loop = 1
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x74, 0x7f, 0xf7]))
            print("Loop is using")
    else:
        if loop == 1:
            loop = 0
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x74, 0x00, 0xf7]))
            print("Loop is closing")
#-----------------------------------------------------------------------------------------------------------------------
#Record LED check
record = 0
def RecordCheck():
    global record
    if transport.isRecording():
        if record == 0:
            record = 1
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x75, 0x7f, 0xf7]))
            print("Record is using")
    else:
        if record == 1:
            record = 0
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x75, 0x00, 0xf7]))
            print("Record is closing")
#-----------------------------------------------------------------------------------------------------------------------
#Play LED check
play = 0
def PlayCheck():
    global play
    if transport.isPlaying():
        if play == 0:
            play = 1
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x76, 0x7f, 0xf7]))
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x77, 0x00, 0xf7]))
            print("Play is using")
    else:
        if play == 1:
            play = 0
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x76, 0x00, 0xf7]))
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x77, 0x7f, 0xf7]))
            print("Play is closing")
#-----------------------------------------------------------------------------------------------------------------------
#Solo LED check
mixerSolo = 0
def MixerSoloCheck():
    global mixerSolo  
    if mixer.isTrackSolo(mixer.trackNumber()):
        if mixerSolo == 0:
            mixerSolo = 1
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1A, 0x7f, 0xf7]))
            print("Mixer Solo is using")
    else:
        if mixerSolo == 1:
            mixerSolo = 0
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1A, 0x00, 0xf7]))
            print("Mixer Solo is closing")
'''
channelSolo = 0
def ChannelSoloCheck():
    global channelSolo  
    if channels.isChannelSolo(channels.selectedChannel()):
        if channelSolo == 0:
            channelSolo = 1
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1a, 0x7f, 0xf7]))
            print("channelSolo is using")
    else:
        if channelSolo == 1:
            channelSolo = 0
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1a, 0x00, 0xf7]))
            print("channelSolo is closing")
'''
#-----------------------------------------------------------------------------------------------------------------------
#Mute LED check
mixerMute = 0
def MixerMuteCheck():
    global mixerMute
    if mixer.isTrackMuted(mixer.trackNumber()):
        if mixerMute == 0:
            mixerMute = 1
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1b, 0x7f, 0xf7]))
            print("Mixer mute is using")
    else:
        if mixerMute == 1:
            mixerMute = 0
            device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1b, 0x00, 0xf7]))
            print("Mixer mute is closing")
#-----------------------------------------------------------------------------------------------------------------------
#Other Button LED Close
def OtherLED_Close():
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x72, 0x00, 0xf7]))        #Rewind LED close
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x73, 0x00, 0xf7]))        #FastForward LED close
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x18, 0x00, 0xf7]))        #Undo LED close
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x19, 0x00, 0xf7]))        #Redo LED close
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1D, 0x00, 0xf7]))        #Song/Pattern mode switch LED close
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1E, 0x00, 0xf7]))        #Edit area switch button LED close
    device.midiOutSysex(bytes([0xf0, 0x00, 0x21, 0x4e, 0x7f, 0x0b, 0xb0, 0x1F, 0x00, 0xf7]))        #Save project button LED close